// pages/game2/game2.js
Page({

  /**
   * 页面的初始数据
   */
  data: {
    success:false,
    num: 0,
    correctnum:0,//做对的题数
    correctrate:0,//正确率
    tihao: Math.round(Math.random()*41),
    dataList:[
        '异曲同工',
        '自圆其说',
        '可圈可点',
        '口是心非',
        '一五一十',
        '里应外合',
        '天方夜谭',
        '四大皆空',
        '四脚朝天',
        '三言两语',
        '正中下怀',
        '马失前蹄',
        '德高望重',
        '事半功倍',
        '胸无点墨',
        '日思夜想',
        '隔岸观火',
        '眉飞色舞',
        '拔苗助长',
        '本末倒置',
        '脱口而出',
        '有气无力',
        '断章取义',
        '扬眉吐气',
        '见缝插针',
        '九牛二虎',
        '平分秋色',
        '牛鬼蛇神',
        '一叶知秋',
        '粗中有细',
        '百里挑一',
        '破门而入',
        '居高临下',
        '身怀六甲',
        '两面三刀',
        '无独有偶',
        '狗尾续貂',
        '人仰马翻',
        '含血喷人',
        '茅塞顿开',
        '一刀两断',
        '兵临城下'
    ],
    tihao_used:[],
    list:['A','B','C','D'],
    btnArr:[],
    memolist:[],
    memoarr:null
  },

  
  onReady: function () {
    this.getData()
  },

  getData(){
    let arr=[];
    let memotemp=null;
    let filterArr = JSON.parse(JSON.stringify(this.data.dataList));
    arr.push(this.data.dataList[this.data.tihao])
    // splice(a,b)a开始删除b个，用完删除，排重
    filterArr.splice(this.data.tihao, 1) 
   
    filterArr.sort(function () {
      return .5 - Math.random();
    }).sort(function () {
      return .5 - Math.random();
      })
    arr = [...arr, ...filterArr.splice(0, 3)].sort(function () {
      return .5 - Math.random();
    })
    memotemp=this.data.dataList[this.data.tihao];
   
    this.data.tihao_used[this.data.tihao]=1;
    this.data.memolist.push(memotemp);
    this.setData({
      memoarr: memotemp,
      btnArr:arr,
      memolist:this.data.memolist,
      tihao_used: this.data.tihao_used
    })
  },
  back() {
    wx.navigateBack({
      delta: 1
    })
  },
  push(event){
      console.log(event.target.dataset.str)
      console.log(this.data.dataList[this.data.tihao])
      console.log(this.data.tihao)
      if (event.target.dataset.str == this.data.dataList[this.data.tihao]){
        console.log('对了')
        var that = this
        wx.showModal({
          title: '提示',
          content: '回答正确',
          confirmText: "下一题",
          success(res) {
            if (res.confirm) {
              if (that.data.num + 1 == 10) {
                that.setData({
                  correctrate: (((that.data.correctnum + 1) / 10) * 100).toFixed(2),
                  success: true
                })
                return
              }
              while(that.data.tihao_used[that.data.tihao]==1){
                that.data.tihao=Math.round(Math.random()*41);
              }
              that.setData({
                num: that.data.num + 1,
                correctnum: that.data.correctnum + 1,
                tihao:that.data.tihao 
              })
              that.getData()
            } else if (res.cancel) {
            }
          }
        })
      }else{
        var that = this
        wx.showModal({
          title: '提示',
          content:that.data.memoarr,
          confirmText: "下一题",
          success(res) {
              if (res.confirm) {
                  if (that.data.num + 1 == 10) {
                    that.setData({
                      correctrate: (((that.data.correctnum) / 10) * 100).toFixed(2),
                      success: true
                    })
                    return
                  }
                    while(that.data.tihao_used[that.data.tihao]==1){
                    that.data.tihao=Math.round(Math.random()*41);
                  }
                  that.setData({
                    num: that.data.num + 1,
                    tihao:that.data.tihao 
                  })
                  that.getData()
                } else if (res.cancel) {
                }
          }
        })
      }
    }
})